<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>爱租屋 - 优质房源推荐</title>
    <link rel="icon" href="../static/img/favicon.ico" type="image/x-icon">
    <!-- Bootstrap core CSS -->
    <link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/bootstrapValidator.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="/static/css/font-awesome.min.css" rel="stylesheet">
    <!-- Custom styles -->
    <link href="/static/css/clean-blog.css" rel="stylesheet">
    <link href="/static/css/zxf_page.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #34495e;
            --accent-color: #e74c3c;
            --light-color: #ecf0f1;
            --dark-color: #222;
            --text-color: #333;
            --light-text: #7f8c8d;
            --border-color: #bdc3c7;
        }

        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            color: var(--text-color);
            background-color: #f5f7fa;
            padding-top: 56px; /* 为固定导航栏留出空间 */
        }

        .navbar {
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            background-color: white;
        }

        .navbar-brand {
            font-weight: 700;
            color: var(--primary-color) !important;
            font-size: 1.8rem;
        }

        .nav-link {
            font-weight: 500;
            color: var(--dark-color) !important;
            transition: color 0.3s;
        }

        .nav-link:hover {
            color: var(--primary-color) !important;
        }

        .masthead {
            background-position: center;
            background-size: cover;
            height: 450px;
            position: relative;
            background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('/static/img/home-bg.jpg');
        }

        .site-heading {
            padding: 180px 0;
            text-align: center;
        }

        .site-heading h1 {
            font-size: 3.5rem;
            font-weight: 700;
            color: white;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
            margin-bottom: 15px;
        }

        .site-heading .subheading {
            font-size: 1.8rem;
            color: rgba(255, 255, 255, 0.9);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        }

        /* 搜索表单容器 */
        .search-container {
            position: relative;
            z-index: 10;
            width: 100%;
            max-width: 900px;
            margin: 0 auto;
        }

        /* 搜索表单样式 */
        #my-form {
            width: 100%;
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            padding: 30px;
            position: relative;
        }

        .search-group {
    display: flex;
    width: 100%;
    margin-bottom: 10px; /* 减小搜索组的底部外边距 */
}

.filter-toggle {
    display: flex;
    justify-content: center;
    margin-top: 5px;
    position: relative; /* 固定位置 */
}

        #txt {
            flex: 1;
            padding: 15px 20px;
            border: 1px solid var(--border-color);
            border-radius: 6px 0 0 6px !important;
            font-size: 18px;
            transition: all 0.3s;
        }

        #txt:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(44, 62, 80, 0.25);
        }

        .my-btn {
            background-color: var(--primary-color) !important;
            border-color: var(--primary-color) !important;
            padding: 15px 30px !important;
            font-weight: 500;
            transition: all 0.3s;
            font-size: 18px;
            border-radius: 0 6px 6px 0 !important;

        }

        .my-btn:hover {
            background-color: var(--secondary-color) !important;
            transform: translateY(-2px);
        }

        /* 搜索建议列表 */
        #list {
            position: absolute;
            width: calc(100% - 60px);
            left: 30px;
            top: calc(100% - 30px); /* 调整位置 */
            z-index: 1000;
            border: 1px solid var(--border-color);
            border-top: none;
            border-radius: 0 0 6px 6px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            max-height: 350px;
            overflow-y: auto;
            background: white;
        }

        .li_style {
            padding: 12px 20px;
            cursor: pointer;
            transition: all 0.2s;
            border-bottom: 1px solid var(--border-color);
            color:grey;search_list.html
        }

        .li_style:hover, .li_style.active {
            background-color: var(--light-color);
            color: var(--primary-color);
        }

        .li_style:last-child {
            border-bottom: none;
        }

        .badge {
            background-color: var(--primary-color);
            color: darkgrey;
            font-weight: 500;
            padding: 6px 10px;
            border-radius: 15px;

        }

        /* 筛选栏样式优化 */
        .filter-toggle {
            display: flex;
            justify-content: center;
            margin-top: 5px;
            position: relative; /* 固定位置 */
        }

        .filter-toggle button {
            background: white;
            border: 1px solid var(--border-color);
            border-radius: 25px;
            padding: 10px 25px;
            font-size: 16px;
            color: var(--primary-color);
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .filter-toggle button:hover {
            background-color: var(--light-color);
        }

        .filter-toggle button i {
            margin-left: 10px;
            transition: transform 0.3s;
        }

        .filter-toggle button.active i {
            transform: rotate(180deg);
        }

        /* 筛选表单样式 - 整体变小 */
        .filter-box {
            background: white;
            border-radius: 12px;
            padding: 15px; /* 减小内边距 */
            margin-top: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            position: relative;
            z-index: 5;
            max-height: 0;
            overflow: hidden;
            opacity: 0;
            transition: all 0.5s ease;
        }

        .filter-box.active {
            max-height: 1000px;
            opacity: 1;
            margin-top: 10px;
        }

        .filter-box label {
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 8px; /* 减小标签间距 */
            font-size: 16px; /* 减小字体大小 */
        }

        .form-control {
            border: 1px solid var(--border-color);
            padding: 10px 12px; /* 减小输入框内边距 */
            border-radius: 6px;
            font-size: 14px; /* 减小字体大小 */
        }

        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(44, 62, 80, 0.25);
        }

        /* 筛选表单布局优化 */
        .filter-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); /* 减小列宽 */
            gap: 15px; /* 减小间距 */
        }

        .filter-group {
            display: flex;
            flex-direction: column;
        }

        .filter-group .form-control {
            margin-top: 6px; /* 减小输入框上边距 */
        }

        .filter-group-row {
            display: flex;
            gap: 10px; /* 减小行内间距 */
        }

        .filter-group-row .form-control {
            flex: 1;
        }

        /* 设施选项样式 */
        .facilities-group {
            margin-top: 10px; /* 减小上边距 */
        }

        .facilities-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); /* 减小设施选项列宽 */
            gap: 10px; /* 减小设施选项间距 */
            margin-top: 8px; /* 减小设施选项上边距 */
        }

        .facility-option {
            display: flex;
            align-items: center;
        }

        .facility-option input[type="checkbox"] {
            margin-right: 6px; /* 减小复选框右边距 */
            cursor: pointer;
            transform: scale(1.1); /* 减小复选框大小 */
        }

        .facility-option label {
            cursor: pointer;
            user-select: none;
            font-size: 14px; /* 减小设施选项字体大小 */
            margin-bottom: 0;
            font-weight: 400;
        }

        /* 区域标签样式 */
        .chanle1, .chanle2 {
            padding: 8px 20px; /* 减小标签内边距 */
            border-radius: 25px;
            margin: 0 6px; /* 减小标签间距 */
            cursor: pointer;
            transition: all 0.3s;
            font-weight: 500;
            font-size: 16px; /* 减小标签字体大小 */
        }

        .chanle1 {
            background-color: var(--primary-color);
            color: white;
        }

        .chanle2 {
            background-color: var(--light-color);
            color: var(--text-color);
        }

        .chanle1.active, .chanle2.active {
            background-color: var(--primary-color);
            color: white;
            box-shadow: 0 2px 8px rgba(44, 62, 80, 0.3);
        }

        /* 当前城市标题 */
        .tj-header h3 {
            color: var(--dark-color);
            font-weight: 700;
            margin-bottom: 15px;
            font-size: 2.2rem;
        }

        .describe {
            color: var(--light-text);
            font-size: 1.2rem;
            margin-bottom: 25px;
        }

        /* 页面内容容器 */
        .container {
            max-width: 1300px;
            padding-top: 40px;
            padding-bottom: 40px;
        }

        /* 房源列表样式 */
        .collection-line {
            background: white;
            border-radius: 12px;
            padding: 30px;
            margin-bottom: 25px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            transition: all 0.3s;
            border: 1px solid var(--border-color);
            display: flex;
            align-items: center;
        }

        .collection-line:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
            border-color: var(--primary-color);
        }

        .collection-line-info .title a {
            color: var(--dark-color);
            font-size: 2rem;
            font-weight: 600;
            transition: color 0.3s;
        }

        .collection-line-info .title a:hover {
            color: var(--primary-color);
            text-decoration: none;
        }

        .attribute-text {
            color: var(--light-text);
            font-weight: 500;
            font-size: 16px;
        }

        .info-text {
            color: var(--text-color);
            font-weight: 500;
            font-size: 16px;
        }

        .img-box {
            border-radius: 8px;
            transition: all 0.3s;
            height: 220px;
            object-fit: cover;
            width: 100%;
        }

        .img-box:hover {
            transform: scale(1.03);
        }

        .price-tag {
            font-size: 2.2rem;
            color: var(--accent-color);
            font-weight: 700;
        }

        /* 分页样式 */
        .my-page-line {
            margin-top: 35px;
        }

        .zxf_pagediv {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-wrap: wrap;
        }

        .zxf_pagediv a, .zxf_pagediv span {
            margin: 0 8px;
            padding: 10px 15px;
            border-radius: 6px;
            color: var(--text-color);
            text-decoration: none;
            transition: all 0.3s;
        }

        .zxf_pagediv a:hover {
            background-color: var(--light-color);
            color: var(--primary-color);
        }

        .zxf_pagediv .current {
            background-color: var(--primary-color);
            color: white;
        }

        /* 页脚样式 */
        footer {
            background-color: var(--dark-color);
            color: white;
            padding: 40px 0;
            margin-top: 60px;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .site-heading h1 {
                font-size: 2.5rem;
            }

            .site-heading .subheading {
                font-size: 1.5rem;
            }

            .collection-line {
                flex-direction: column;
            }

            .img-box {
                margin-bottom: 25px;
            }

            #list {
                width: calc(100% - 45px);
                left: 22.5px;
            }
        }

        /* 美化筛选表单 */
        .filter-box {
            border: 1px solid var(--border-color);
            background-color: #f9f9f9;
        }

        .filter-group {
            background-color: white;
            padding: 15px; /* 减小筛选组内边距 */
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .facilities-group {
            background-color: white;
            padding: 15px; /* 减小设施组内边距 */
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

    </style>
</head>

<body>

<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
    <div class="container">
        <a class="navbar-brand" href="http://127.0.0.1:5000/">爱租屋</a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
                data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false"
                aria-label="Toggle navigation">
            <i class="fas fa-bars"></i>
        </button>

        <div class="collapse navbar-collapse" id="navbarResponsive">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item">
                    <a class="nav-link" href="http://127.0.0.1:5000/">首页</a>
                </li>

                {% if request.cookies.get('is_logged_in') == 'true' %}
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        {{ request.cookies.get('username') }}
                    </a>
                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="/user/{{ request.cookies.get('username') }}">个人中心</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/logout">注销</a>
                    </div>
                </li>
                {% else %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="modal" data-target="#login" href="#">
                        <i class="fas fa-sign-in-alt"></i> 登录
                    </a>
                </li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>

<!-- Page Header -->
<header class="masthead" style="background-image: url('/static/img/home-bg.jpg')">
    <div class="overlay"></div>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-md-10 mx-auto">
                <div class="site-heading">
                    <h1>发现您的理想之家</h1>
                    <span class="subheading">精选优质二手房源，为您提供最佳选择</span>

                    <!-- 搜索区域 -->
                    <div class="search-container mt-4">
                        <ul class="nav nav-tabs my-nav-tabs justify-content-center mb-3">
                            <li class="chanle1 active"><span>地区搜索</span></li>
                        </ul>

                        <form class="form-inline justify-content-center" role="form" id="my-form" action="http://127.0.0.1:5000/query" method="post">
                            <!-- 搜索框和按钮在同一行 -->

                            <div class="search-group mb-4">
                                <input type="text" class="form-control" id="txt" name="addr" placeholder="请输入区域、商圈或小区名开始找房" value="{{ addr or '' }}">
                                <button type="submit" class="my-btn btn" id="btn">
                                    <i class="fa fa-search"></i> 搜索
                                </button>
                            </div>

                            <div><ul id="list" class="list-group"></ul></div>

                            <!-- 筛选栏切换按钮 - 固定在第二行 -->
                            <div class="filter-toggle">
                                <button id="filter-toggle-btn">
                                    高级筛选 <i class="fa fa-chevron-down"></i>
                                </button>
                            </div>

                            <!-- 筛选表单 -->
                            <div class="filter-box" id="filter-box">
                                <div class="filter-grid">
                                    <!-- 左侧筛选条件 -->
                                    <div class="filter-group">
                                        <label for="rooms-filter">户型:</label>
                                        <select class="form-control" id="rooms-filter" name="rooms">
                                            <option value="" {% if not rooms %}selected{% endif %}>全部户型</option>
                                            <option value="1室1厅" {% if rooms=='1室1厅' %}selected{% endif %}>1室1厅</option>
                                            <option value="2室1厅" {% if rooms=='2室1厅' %}selected{% endif %}>2室1厅</option>
                                            <option value="2室2厅" {% if rooms=='2室2厅' %}selected{% endif %}>2室2厅</option>
                                            <option value="3室1厅" {% if rooms=='3室1厅' %}selected{% endif %}>3室1厅</option>
                                            <option value="3室2厅" {% if rooms=='3室2厅' %}selected{% endif %}>3室2厅</option>
                                            <option value="4室1厅" {% if rooms=='4室1厅' %}selected{% endif %}>4室1厅</option>
                                            <option value="4室2厅" {% if rooms=='4室2厅' %}selected{% endif %}>4室2厅</option>
                                            <option value="5室及以上" {% if rooms=='5室及以上' %}selected{% endif %}>5室及以上</option>
                                        </select>
                                    </div>

                                    <div class="filter-group">
                                        <label>面积(m²):</label>
                                        <div class="filter-group-row">
                                            <input type="number" class="form-control" id="area-min" name="area_min" placeholder="最小" value="{{ area_min or '' }}">
                                            <input type="number" class="form-control" id="area-max" name="area_max" placeholder="最大" value="{{ area_max or '' }}">
                                        </div>
                                    </div>

                                    <div class="filter-group">
                                        <label>价格(元):</label>
                                        <div class="filter-group-row">
                                            <input type="number" class="form-control" id="price-min" name="price_min" placeholder="最低" value="{{ price_min or '' }}">
                                            <input type="number" class="form-control" id="price-max" name="price_max" placeholder="最高" value="{{ price_max or '' }}">
                                        </div>
                                    </div>

                                    <!-- 设施选项 -->
                                    <div class="filter-group facilities-group">
                                        <label>设施:</label>
                                        <div class="facilities-grid">
                                            <div class="facility-option">
                                                <input type="checkbox" id="fridge" name="facilities" value="冰箱" {% if '冰箱' in facilities %}checked{% endif %}>
                                                <label for="fridge">冰箱</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="washer" name="facilities" value="洗衣机" {% if '洗衣机' in facilities %}checked{% endif %}>
                                                <label for="washer">洗衣机</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="tv" name="facilities" value="电视" {% if '电视' in facilities %}checked{% endif %}>
                                                <label for="tv">电视</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="ac" name="facilities" value="空调" {% if '空调' in facilities %}checked{% endif %}>
                                                <label for="ac">空调</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="heating" name="facilities" value="暖气" {% if '暖气' in facilities %}checked{% endif %}>
                                                <label for="heating">暖气</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="water-heater" name="facilities" value="热水器" {% if '热水器' in facilities %}checked{% endif %}>
                                                <label for="water-heater">热水器</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="gas" name="facilities" value="天然气" {% if '天然气' in facilities %}checked{% endif %}>
                                                <label for="gas">天然气</label>
                                            </div>
                                            <div class="facility-option">
                                                <input type="checkbox" id="wifi" name="facilities" value="Wi-Fi" {% if 'Wi-Fi' in facilities %}checked{% endif %}>
                                                <label for="wifi">Wi-Fi</label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Main Content -->
<div class="container">
    <!-- 当前城市房源 -->
    <div class="row info-line">
        <div class="col-lg-12 tj-header">
            <h3>为您精选</h3>
            <div class="describe">
                <span>当前城市优质房源信息</span>
            </div>
        </div>

        <!-- 房源列表 -->
        <div class="collection col-lg-12">
            <div id="fill-data" class="{{ page_num }}">
                {% for house in house_list %}
                <div class="row collection-line">
                    <div class="col-lg-5 col-md-5">
                        <a href="/house/{{ house.id }}">
                            <img class="img-fluid img-box" src="{{ url_for('static', filename='img/house-gb.jpg') }}" alt="{{ house.title }}">
                        </a>
                    </div>
                    <div class="col-lg-5 col-md-5">
                        <div class="collection-line-info">
                            <div class="title mb-3">
                                <a href="/house/{{ house.id }}">{{ house.title | dealover }}</a>
                            </div>
                            <div class="mb-2">
                                <span class="attribute-text">地址：</span>
                                <span class="info-text">{{ house.address }}</span>
                            </div>
                            <div class="mb-2">
                                <span class="attribute-text">面积：</span>
                                <span class="info-text">{{ house.area }} m²</span>
                            </div>
                            <div class="mb-2">
                                <span class="attribute-text">户型：</span>
                                <span class="info-text">{{ house.rooms }}</span>
                            </div>
                            <div class="mb-2">
                                <span class="attribute-text">朝向：</span>
                                <span class="info-text">{{ house.direction }}</span>
                            </div>
                            <div class="mb-2">
                                <span class="attribute-text">交通：</span>
                                <span class="info-text">{{ house.traffic | dealdirection }}</span>
                            </div>
                            <div class="mt-3">
                                <span class="attribute-text">
                                    <i class="fa fa-heart text-danger"></i> {{ house.page_views }} 次浏览
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 d-flex flex-column justify-content-between align-items-end">
                        <div class="price-tag mb-3">￥{{ house.price }}</div>
                        <a href="/house/{{ house.id }}" class="btn btn-outline-primary">
                            查看详情 <i class="fa fa-arrow-right"></i>
                        </a>
                    </div>
                </div>
                {% endfor %}
            </div>

            <!-- 分页 -->
            <div class="row my-page-line">
                <div class="col-lg-12">
                    <div class="zxf_pagediv">
                        <span class="disabled">上一页</span>
                        <span class="current">1</span>
                        <a href="javascript:;" class="zxfPagenum nextpage">2</a>
                        <a href="javascript:;" class="zxfPagenum">3</a>
                        <a href="javascript:;" class="zxfPagenum">4</a>
                        <a href="javascript:;" class="zxfPagenum">5</a>
                        <a href="javascript:;" class="zxfPagenum">6</a>
                        <a href="javascript:;" class="zxfPagenum">7</a>
                        <a href="javascript:;" class="zxfPagenum">8</a>
                        <a href="javascript:;" class="zxfPagenum">9</a>
                        <span>...</span>
                        <a href="javascript:;" class="nextbtn">下一页</a>
                        <span>共<b>11332</b>页，</span>
                        <span>到第<input type="number" class="zxfinput" value="">页</span>
                        <span class="zxfokbtn">确定</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 注册模态框 -->
<div id="register" class="modal fade login_form" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body m-header">
                <button class="close" data-dismiss="modal">
                    <span>×</span>
                </button>
            </div>
            <div class="modal-title">
                <h1 class="text-center">注册账号</h1>
            </div>
            <div class="modal-body">
                <form class="form-group" id="registeform" action="http://127.0.0.1:5000/register" method="post">
                    <div class="form-group">
                        <label class="form-info">用户名</label>
                        <input class="form-control" name="username" type="text" placeholder="6-15位字母或数字">
                    </div>
                    <div class="form-group">
                        <label class="form-info">密码</label>
                        <input class="form-control" name="password" type="password" placeholder="至少6位字母或数字">
                    </div>
                    <div class="form-group">
                        <label class="form-info">确认密码</label>
                        <input class="form-control" name="confirmPassword" type="password" placeholder="再次输入密码">
                    </div>
                    <div class="form-group">
                        <label class="form-info">邮箱</label>
                        <input class="form-control" name="email" type="email" placeholder="例如:123@123.com">
                    </div>
                    <div class="text-center mt-4">
                        <button class="btn btn-primary mr-3" id="registe-btn">注册</button>
                        <button class="btn btn-outline-secondary" data-dismiss="modal">取消</button>
                    </div>
                    <a href="#" data-toggle="modal" data-dismiss="modal" data-target="#login" class="switch-info">已有账号？点我登录</a>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 登录模态框 -->
<div id="login" class="modal fade login_form">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body m-header">
                <button class="close" data-dismiss="modal">
                    <span>×</span>
                </button>
            </div>
            <div class="modal-title">
                <h1 class="text-center">用户登录</h1>
            </div>
            <div class="modal-body">
                <form class="form-group" id="loginform" action="http://127.0.0.1:5000/login" method="post">
                    <div class="form-group">
                        <label class="form-info">用户名</label>
                        <input class="form-control" name="username" type="text" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label class="form-info">密码</label>
                        <input class="form-control" name="password" type="password" placeholder="请输入密码">
                    </div>
                    <div class="text-center mt-4">
                        <button class="btn btn-primary mr-3" id="login-btn">登录</button>
                        <button class="btn btn-outline-secondary" data-dismiss="modal">取消</button>
                    </div>
                    <a href="#" data-toggle="modal" data-dismiss="modal" data-target="#register" class="switch-info">还没有账号？点我注册</a>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-md-10 mx-auto text-center">
                <p class="copyright">© 2023 二手好房 版权所有</p>
            </div>
        </div>
    </div>
</footer>

<!-- Bootstrap core JavaScript -->
<script src="/static/vendor/jquery/jquery.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/static/js/bootstrapValidator.min.js"></script>
<script src="/static/js/login.js"></script>
<script src="/static/js/zxf_page.js"></script>
<script src="/static/js/clean-blog.min.js"></script>

<script>
    $(document).ready(function () {
        // 筛选栏切换功能
        const filterToggleBtn = $('#filter-toggle-btn');
        const filterBox = $('#filter-box');

        // 初始化筛选栏状态（默认隐藏）
        filterBox.removeClass('active');
        filterToggleBtn.removeClass('active');

        filterToggleBtn.on('click', function (e) {
            e.preventDefault(); // 阻止按钮的默认行为
            filterBox.toggleClass('active');
            filterToggleBtn.toggleClass('active');
        });

        // 分页初始化
        $(".zxf_pagediv").createPage({
            pageNum: {{ total_num }},
            current: Number($('#fill-data').attr('class')),
            backfun: function (e) {
                console.log(e['current']);
                var n_current = e['current'];
                var form = $('#my-form');
                form.append('<input type="hidden" name="page" value="' + n_current + '">');
                form.submit();
                $('input[name="page"]').remove();
            }
        });

        // 户型搜索切换
        $(".chanle2").on('click', function () {
            if ($('.chanle2').hasClass('active')) {
                resetSearchType();
            } else {
                $(".chanle1").removeClass('active');
                $(".chanle2").addClass('active');
                $("#txt").attr('name', 'rooms');
                $('#txt').attr('placeholder', '请输入户型开始找房，例如:1室1厅');
            }
            clearSuggestions();
        });

        // 重置搜索类型
        function resetSearchType() {
            $(".chanle1").removeClass('active');
            $(".chanle2").removeClass('active');
            $("#txt").attr('name', '');
            $('#txt').attr('placeholder', '');
            $("#txt").val('');
            clearSuggestions();
        }

        // 清空建议列表
        function clearSuggestions() {
            $("#list").empty();
        }

        // 输入框事件处理
        var oTxt = document.getElementById('txt');
        var oBtn = document.getElementById('btn');
        var oList = document.getElementById('list');
        var cpLock = false;

        $('#txt').on('compositionstart', function () {
            cpLock = true;
        });

        $('#txt').on('compositionend', function () {
            cpLock = false;
            var keyWord = oTxt.value;
            searchByIndexOf(keyWord);
        });

        $('#txt').on('input', function () {
            if (!cpLock) {
                var keyWord = oTxt.value;
                searchByIndexOf(keyWord);
            }
        });

        oBtn.addEventListener('click', function () {
            var keyWord = oTxt.value;
            if (keyWord.trim() === '') return;
            searchByIndexOf(keyWord);
        }, false);

        oTxt.addEventListener('click', function (e) {
            var keyWord = oTxt.value;
            if (keyWord.trim() === '') return;
            searchByIndexOf(keyWord);
            filterBox.removeClass('active');
            filterToggleBtn.removeClass('active');
        });

        oTxt.addEventListener('keydown', function (e) {
            if (e.keyCode == 13) {
                var keyWord = oTxt.value;
                if (keyWord.trim() === '') return;
                searchByIndexOf(keyWord);
            }
        }, false);

        $(document).on('click', function (e) {
            if (!$(e.target).closest('#txt, #list').length) {
                clearSuggestions();
            }
        });

        // 搜索关键字
        function searchByIndexOf(keyWord) {
            if (keyWord.trim() === '') {
                clearSuggestions();
                return;
            }

            $(".my-nav-tabs li").each(function (index, element) {
                if ($(this).hasClass("active")) {
                    var info = $(this).text();
                    var data = {"kw": keyWord, "info": info};

                    $.ajax({
                        url: "/search/keyword/",
                        type: 'post',
                        dataType: 'json',
                        data: data,
                        success: function (response) {
                            if (response['code'] == 0) {
                                clearSuggestions();
                            } else if (response['code'] == 1) {
                                var list = response['info'];
                                console.log('search', list);

                                oList.innerHTML = '';
                                var item = null;
                                var maxItems = Math.min(list.length, 9);

                                for (var i = 0; i < maxItems; i++) {
                                    item = document.createElement('li');
                                    item.setAttribute("class", "list-group-item li_style");
                                    item.setAttribute("title", list[i]['t_name']);

                                    var li_text = list[i]['t_name'] + '<span class="badge float-right">大约有' + list[i]['num'] + '套房</span>';
                                    item.innerHTML = li_text;

                                    oList.appendChild(item);
                                }

                                bindSuggestionClickEvents();
                            }
                        },
                        error: function () {
                            clearSuggestions();
                            console.error("搜索请求失败");
                        }
                    });
                }
            });
        }

        // 绑定建议项点击事件
        function bindSuggestionClickEvents() {
            $('.li_style').on('click', function () {
                $('.li_style').removeClass('active');
                $(this).addClass('active');
                var t_name = $(this).attr('title');
                $('#txt').val(t_name);
                clearSuggestions();
            });
        }

        // 表单提交前处理设施数据
        $('#my-form').on('submit', function (e) {
            var selectedFacilities = [];
            $('input[name="facilities"]:checked').each(function () {
                selectedFacilities.push($(this).val());
            });

            if (selectedFacilities.length > 0) {
                $(this).append('<input type="hidden" name="facilities_str" value="' + selectedFacilities.join(',') + '">');
            }
        });
    });
</script>

</body>
</html>